<?php
$db = new Database;
$auth = Auth::getAuth('current_user');
$user_id = $auth['id'];
$company_id = $auth['company_id'];
$data = "";
$timezone = "Asia/Manila";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
if(isset($_POST['action'])){
    if($_POST['action']=="saveFormUser"){
        if($_POST['submitType']==1){
            //echo "submit";
            $status = 0;
        }else if($_POST['submitType']==2){
            //echo "draft";
            $status = 4;
        }
        $arrayData = explode(",",implode(",",$_POST['arrayData']));
        $form_id = $_POST['activeFormForRequest'];
        for($a=0;$a<count($arrayData);$a++){
            $data.=$arrayData[$a]."~";
        }
        $insertRequest = array(
                "user_id"=>$user_id,
                "company_id"=>$company_id,
                "form_id"=>$form_id,
                "data"=>$data,
                "status"=>$status,
                "date"=>date("Y-m-d H:i:s"),
        );
        $request_id = $db->insert("tbrequest",$insertRequest);
        echo $request_id;
    }else if($_POST['action']=="updateDraftRequest"){
        $request_id = $_POST['request_id'];
        $arrayData = explode(",",implode(",",$_POST['arrayData']));
        for($a=0;$a<count($arrayData);$a++){
            $data.=$arrayData[$a]."~";
        }
        $update = array(
            "data"=>$data
            );
        $condition = array(
            "id"=>$request_id
            );
        $db->update("tbrequest",$update,$condition);
    }
}
?>